package com.itheima.manager.dao;

import com.itheima.manager.domain.Student;

import java.util.ArrayList;

public class StudentDao implements BaseStudentDao{
    private static ArrayList<Student> list = new ArrayList<>();

    static {
        System.out.println("system");
        list.add(new Student("heima001","张三","23","1999-1-1"));
    }


    public void addStudent(Student stu) {
        list.add(stu);
    }

    public ArrayList<Student> findAllStudent() {

        return list;
    }

    public boolean deleteStudent(String sSid) {

        int index = getIndex(sSid);

        if(index == -1){
            return false;
        }else {
            list.remove(index);
            return true;
        }
    }

    public int getIndex(String sSid) {

        int index = -1;

        for (int i = 0; i < list.size(); i++) {

            if(sSid.equals(list.get(i).getId())){

                index = i;

                break;

            }
        }
        return index;
    }

    //修改学生方法
    public void updateStudent(String updateId, Student newStu) {
        int index = getIndex(updateId);
        list.set(index,newStu);
    }
}
